import React from "react"
import { connect } from "react-redux" 
import OrderView from "./OrderView"
import UserView from "./UserView"
import ShopCarHeader from "../../component/Header"
import * as collectActions from '../../actions/collect'
import {bindActionCreators} from 'redux'
import orderHttp from "../../api/order"
function* generatorFn(){
    yield "hello";
    yield "world";
    yield "ending";
}
const hg = generatorFn();
class ShopCar extends React.Component{
    constructor(props){
        super(props)
        this.state={
            orderArry : []
        }
    }
    componentDidMount(){
        if(!this.props.isLogin){
            /**
             * 路由重定向到登录页面
             */
            this.props.history.push("/login")
        }else{
            /**
             * 在这里请求订单信息
             */
            orderHttp.getOrder('kaikeba').then(data=>{
                this.setState({
                    orderArry:data
                })
            })
        }
    }
    render(){
        return(
            <div>
                <ShopCarHeader title="购物车"/>
                <UserView user="kaikeba" city={this.props.city.cityName}/>
                <OrderView data={this.state.orderArry}/>
            </div>
        )
    }
}

function mapStateToProps(state){
    return{
        isLogin:state.user.isLogin,
        city:state.city
    }
}
const mapDispatchToProps = dispatch=>{
    return {
        collectActions:bindActionCreators(collectActions,dispatch)
    }
}
export default connect(
    mapStateToProps,
    mapDispatchToProps
)(ShopCar)